home *** CD-ROM | disk | FTP | other *** search
- # SpecTcl, by S. A. Uhler
- # Copyright (c) 1994-1995 Sun Microsystems, Inc.
- #
- # See the file "license.txt" for information on usage and redistribution
- # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- #
- # toolbar management routines
-
- # create the toolbar. Its hardwired for now, but should be user programmable
- # Each toolbar has 3 procedures:
- # setup_<tool> - to setup the toolbar (optional)
- # sync_<tool> win [options...] - to make tool value current with "win"
- # set_<tool> win - to make the tool take affect
-
- proc create_toolbar {win} {
- global P
- set column 0 ;# which column
-
- # The current item's text or label field
-
- label .text_label -text text
- blt_table $win .text_label 0,[incr column]
- entry .entry -textvariable Current(text) -relief ridge -width 15 -state disabled
- blt_table $win .entry 0,[incr column]
-
- # set up bindings for immediate action on text entry
-
- bind fast <Delete> {change_entry %W}
- bind fast <BackSpace> {change_entry %W}
- bind fast <Return> "
- %W insert insert {\n}
- change_entry %W
- "
- bind fast <Key> {
- if {[string length %A] > 0} {change_entry %W}
- }
-
- bindtags .entry "[bindtags .entry] fast"
- bind .entry <Return> {change_entry %W}
-
- foreach i {Left Right} {
- bind .entry <$i> "short_cut $i;break"
- }
-
- # the packing anchor
-
- setup_anchor .anchor Anchor set_anchor
- blt_table $win .anchor 0,[incr column]
-
- # the packing fill
-
- setup_fill .fill Fill set_fill
- blt_table $win .fill 0,[incr column]
-
- # the text justification
-
- setup_justify .justify just set_just
- blt_table $win .justify 0,[incr column]
-
- # the relief setting
-
- frame .relief -bd 2 -relief ridge
- frame .relief.inside -bd 3 -bg grey -width 12 -height 12
- blt_table $win .relief 0,[incr column] -padx 1 -pady 1
- blt_table .relief .relief.inside 0,0 -padx 1 -pady 1 -fill both
- bind .relief.inside <1> {setup_reliefs %W.1 "set_relief %W"}
-
- # the font style
-
- label .style -bd 2 -relief ridge -text A
- blt_table $win .style 0,[incr column] -padx 2 -pady 2
- bind .style <1> "next_text_style %W"
- # bind .style <1> "setup_style Fontstyle %W"
-
- # the foreground and background color
-
- label .fgcolor -bd 2 -relief ridge -text fg
- blt_table $win .fgcolor 0,[incr column] -padx 2 -pady 2
- bind .fgcolor <1> "setup_colors %W.1 Colors {set_color %W foreground}"
-
- label .bgcolor -bd 2 -relief ridge -text bg
- blt_table $win .bgcolor 0,[incr column] -padx 2 -pady 2
- bind .bgcolor <1> "setup_colors %W.1 Colors {set_color %W background}"
-
- # font size menu - too slow for testing
- setup_fontsize .font_size Fontsize set_fontsize
- blt_table $win .font_size 0,[incr column]
-
- setup_borderwidth .borderwidth Borderwidth set_borderwidth
- blt_table $win .borderwidth 0,[incr column]
-
- setup_orient .orient Orient set_orient
- blt_table $win .orient 0,[incr column]
- }
-
- # this is the list of toolbars
-
- set Toolbar {
- entry anchor fill justify relief style fgcolor
- bgcolor font_size borderwidth orient
- }
-
- ####################################################################
- # update the setting of the toolbars to reflect the current widget
-
- # update the data in the current widget and its array
- # This one is invoked during keystrokes via the bindings
-
- proc change_entry {win} {
- global P Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
-
- foreach item {text label} {
- if {[catch {$widget cget -$item}]} continue
- $widget configure -$item $Current(text)
- sync_form $item $Current(text)
- }
- return 1
- }
-
- # reflect text of current widget into entry field
-
- proc sync_entry {win} {
- global Current P
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set text [$widget cget -text]}] && \
- [catch {set text [$widget cget -label]}]} {
- $win configure -state disabled
- set Current(text) ""
- return 0
- } else {
- set Current(text) $text
- $win configure -state normal
- $win selection range 0 end
- return 1
- }
- }
-
- proc sync_anchor {win} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- array set options [blt_table info $widget]
- if {$options(-anchor) == "center"} {set options(-anchor) "c"}
- $win configure -image $options(-anchor)_anchor
- }
-
- proc sync_fill {win} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- array set options [blt_table info $widget]
- $win configure -image $options(-fill)_fill
- }
-
- proc sync_borderwidth {win} {
- global Current Borderwidth
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set Borderwidth [$widget cget -bd]}]} {
- $win configure -state disabled
- } else {
- $win configure -state normal
- }
- }
-
- proc sync_justify {win} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set justify [$widget cget -justify]}]} {
- $win configure -state disabled
- } else {
- $win configure -image ${justify}_just -state normal
- }
- }
-
- proc sync_relief {win} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- set relief [$widget cget -relief]
- $win.inside configure -relief $relief
- }
-
- proc sync_fgcolor {win} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set color [$widget cget -fg]}]} {
- } else {
- $win configure -fg [contrast_color $color] -bg $color
- }
- }
-
- proc sync_bgcolor {win} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set color [$widget cget -bg]}]} {
- } else {
- $win configure -fg [contrast_color $color] -bg $color
- }
- }
-
- proc sync_style {win} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set font [$widget cget -font]}]} {
- $win configure -bg grey
- } else {
- InFilter_font font
- set current [$win cget -font]
- InFilter_font current
- regexp {([^,]*,[^,]*),*(.*)} $font dummy base style
- regexp {([^,]*,[^,]*),*(.*)} $current dummy c_base c_style
- set font $c_base,$style
- OutFilter_font dymmy font font
- $win configure -font $font -bg [[winfo parent $win] cget -bg]
- }
- }
-
- proc sync_font_size {win} {
- global Current Fontsize
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set font [$widget cget -font]}]} {
- $win configure -bg grey
- } else {
- $win configure -bg [[winfo parent $win] cget -bg]
- InFilter_font font
- regexp {([^,]*),([^,]*),*(.*)} $font dummy family size style
- set Fontsize $size
- }
- }
-
- # now sync all of the toolbars
-
- proc sync_all {win} {
- global Toolbar
- foreach i $Toolbar {
- sync_$i $win.$i
- }
- }
-
- ######################################################################
- # set the anchor value - need to update the form too
-
- proc set_anchor {style} {
- global Current
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- catch "blt_table configure $widget -anchor $style"
- sync_form align $style
- set Current(repeat) "set_anchor $style"
- }
-
- # set the fill value - need to update the form too
-
- proc set_fill {style} {
- global Current
- set bad [catch "blt_table configure $Current(widget) -fill $style"]
- if {$bad} {
- global _Message
- set _Message "This item has no \"fill\" option"
- } else {
- sync_form fill $style
- }
- set Current(repeat) "set_fill $style"
- }
-
- # set the justify value - need to update the form too
-
- proc set_just {style} {
- global Current
- set bad [catch "$Current(widget) configure -justify $style"]
- if {$bad} {
- global _Message
- set _Message "This item has no \"justify\" option"
- } else {
- sync_form fill $style
- }
- set Current(repeat) "set_just $style"
- }
-
- # set the border size - need to update the form too
-
- proc set_borderwidth {style} {
- global Current Borderwidth
- set bad [catch "$Current(widget) configure -bd $style"]
- if {$bad} {
- global _Message
- set _Message "This item has no \"borderwidth\" option"
- } else {
- sync_form borderwidth $style
- }
- set Current(repeat) "set_borderwidth $style"
- }
-
- # set the font size
-
- proc set_fontsize {size} {
- global Current _Message Fontsize
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set font [$widget cget -font]}]} {
- set _Message "This item has no \"font size\" option"
- return
- }
- InFilter_font font
- regexp {([^,]*),([^,]*),*(.*)} $font dummy family size style
- set font $family,$Fontsize,$style
- if {![OutFilter_font dummy font font]} {
- set _Message "font size $Fontsize is invalid for $family,$style"
- return
- }
- $widget configure -font $font
- sync_form font $font
- set Current(repeat) "set_fontsize $size"
- }
-
- # set the color value - need to update the form too
-
- proc set_color {win what style} {
- global Current
- set bad [catch "$Current(widget) configure -$what $style"]
- if {$bad} {
- global _Message
- set _Message "This item has no \"$what\" color option"
- } else {
- $win configure -bg $style -fg [contrast_color $style]
- sync_form $what $style
- # heuristic
- if {$what == "foreground" && [catch { \
- $Current(widget) configure -activeforeground $style}] == 0} {
- sync_form activeforeground $style
- }
- }
- set Current(repeat) "set_color $win $what $style"
- }
-
- # set the selected widget (and toolbar icon) to the proper relief
-
- proc set_relief {win relief} {
- global Current _Message
-
- $win configure -relief $relief
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- $widget configure -relief $relief
- sync_form relief $relief
- set Current(repeat) "set_relief $relief"
- }
-
- #########################################
- # procedure to create border size menu
-
- proc setup_borderwidth {win name {command puts}} {
- global _Message
- upvar #0 $name var
- if {![info exists var]} {set var 2}
- menubutton $win -menu $win.borderwidth -width 2 \
- -textvariable $name -bd 2 -relief ridge -padx 1 -pady 1
- menu $win.borderwidth
- foreach item {0 1 2 4 8 12} {
- $win.borderwidth add command -label $item -command "
- set $name $item
- eval \"$command $item\"
- "
- }
- }
-
- # select orientation (scrollbars and scales only) - placeholder
-
- proc setup_orient {win name {command puts}} {
- global _Message
- upvar #0 $name var
- if {![info exists var]} {set var v}
- menubutton $win -menu $win.orient \
- -textvariable $name -bd 2 -relief ridge -padx 1 -pady 1
- menu $win.orient
- foreach item {vertical horizontal} {
- $win.orient add command -label $item -command "
- set $name [string range $item 0 0]
- eval \"$command $item\"
- "
- }
- }
-
- proc sync_orient {win} {
- global Current Orient
- if {[set widget $Current(widget)] == ""} {
- return 0
- }
- if {[catch {set orient [$widget cget -orient]}]} {
- $win configure -state disabled
- } else {
- set Orient [string range $orient 0 0]
- $win configure -state normal
- }
- }
-
- proc set_orient {style} {
- global Current Orient
- set bad [catch "$Current(widget) configure -orient $style"]
- if {$bad} {
- global _Message
- set _Message "This item has no \"orient\" option"
- } else {
- sync_form orient $style
- orient_create $Current(widget)
- }
- }
-